package com.dubbo.boot.provider.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.dubbo.bean.Order;
import com.dubbo.service.UserService;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.stereotype.Component;

import java.util.Arrays;
import java.util.List;
import java.util.UUID;

/**
 * @author by Mr. Li 2020/11/20 13:35
 */
//@Service spring 家的 注解 这里需要使用dubbo 提供的service 进行服务的暴露
@Service
@Component
public class UserServiceImpl implements UserService {


    @Override
    @HystrixCommand
    public List<Order> getUserAddressList(int orderId) {
        Order orderById = new Order(orderId, "上海市，青浦区", "小刚", UUID.randomUUID().toString());
        System.out.println(orderById);
        // 设置服务降级
        if (Math.random() < 0.5) {
            throw new RuntimeException("服务走降级");
        }
        return Arrays.asList(orderById);
    }

}
